import { Form } from 'antd';
import { useDescriptionsType } from '@/components/DescriptionsType';
import { getFileNameByPath, wordHandChildParamContract } from '@/utils';
import { useContext } from 'react';
import { ConractControllerContext } from '../common';
import { FormOutlined } from '@ant-design/icons';

const getOnlyEditingTempConfig = (onNtkoReadWord: (url: string, urlRecord: Record<string, any>, onlyRead?: boolean) => void) => {
  const [onlyEditForm] = Form.useForm();

  const { contractForm, counterpartRows } = useContext(ConractControllerContext);

  /** 表单配置 */
  const [config, methods] = useDescriptionsType({
    labelWidth: 190,
    basicForm: onlyEditForm,
    schemas: [
      {
        key: 'contract-tempInfo',
        title: '合同正文',
        fieldChildren: [
          {
            field: `onluEditing`,
            label: `合同正文`,
            component: 'Render',
            colSpan: 2,
            slotRender: () => {
              const contractName = contractForm?.getFieldValue('contractURL') ? getFileNameByPath(contractForm?.getFieldValue('contractURL')) : '';

              /** 获取相对方列表 */
              const oppositeList: Record<string, any>[] = contractForm?.getFieldValue('oppositeList');

              return (
                <div style={{ width: '100%', display: 'flex', padding: 10 }}>
                  {contractName ? (
                    <>
                      <a>{contractName}</a>
                      <a
                        onClick={() => {
                          onNtkoReadWord(
                            'contractURL',
                            wordHandChildParamContract({
                              ...contractForm?.getFieldsValue(),
                              oppositeList: counterpartRows,
                            }),
                            false,
                          );
                        }}
                        style={{
                          marginLeft: 20,
                        }}
                      >
                        <FormOutlined />
                      </a>
                    </>
                  ) : (
                    <span>--</span>
                  )}
                </div>
              );
            },
            //
          },
        ],
      },
    ],
  });

  return {
    config,
    methods,
  };
};

export { getOnlyEditingTempConfig };
